/**
 * Created by xiongxin on 2017/11/15.
 */


import axios from 'axios'
import urlAll from './kj_url';


//格式化时间；
Date.prototype.Format = function (fmt) {
  var o = {
    "M+": this.getMonth() + 1, //month
    "d+": this.getDate(), //day
    "h+": this.getHours(), //hour
    "m+": this.getMinutes(), //minute
    "s+": this.getSeconds(), //second
    "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
    "S": this.getMilliseconds() //millisecond
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
};

function sendService(url, options, fn) {
  // var myDate = new Date();
  // var trandt = myDate.Format("yyyyMMdd");
  // var trantm = myDate.Format("hhmmss");
  loadPop.show();
  $.ajax({
    headers: {
      // "clentid": urlAll.clientid,
      // "userid": Local.get('userId'),
      // "trandt": trandt,
      // "trantm": trantm,
      // "chnflg": 1,
      // "acton": Local.get('token')
    },
    //url: 'https://openapi.boc.cn/card/query_card_list',
    url: url,
    type: 'POST',
    contentType: "content-type-application/json; charset=utf-8",
    dataType: 'json',
    // data: JSON.stringify({
    //   'cardSeq':  3017101252536110
    // }),
    data:JSON.stringify( options ) || '',
    timeout: 10000,
    success: function (data) {
      if(data.status == 'success'){
        loadPop.hide();
        //loadPop.show();
        if (fn) {
          fn(data);
        }
      }

    },
    error: function (e) {
      loadPop.hide();
      console.log('显示网络异常！')
    }
    //超时处理
  })
}



export default {
  sendService
};

